package com.atguigu.spring.springmvc;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 定义一个Adapter接口
 * @create: 2022-02-14 11:19
 **/
public interface HandlerAdapter {

	public boolean supports(Object handler);

	public void handle(Object handler);
}

/**
 * 多种适配器类
 */
class SimpleHandlerAdapter implements HandlerAdapter {

	public void handle(Object handler) {
		((SimpleController) handler).doSimplerHandler();
	}

	public boolean supports(Object handler) {
		return (handler instanceof SimpleController);
	}

}

/**
 * 相当于每一个Controller对应一个适配器
 */
class HttpHandlerAdapter implements HandlerAdapter {

	public void handle(Object handler) {
		((HttpController) handler).doHttpHandler();
	}

	public boolean supports(Object handler) {
		return (handler instanceof HttpController);
	}

}

class AnnotationHandlerAdapter implements HandlerAdapter {

	public void handle(Object handler) {
		((AnnotationController) handler).doAnnotationHandler();
	}

	public boolean supports(Object handler) {

		return (handler instanceof AnnotationController);
	}

}